#include "elabstractbutton.h"
#include "elicon.h"
#include "eltheme.h"

ElAbstractButton::ElAbstractButton(QWidget *parent)
    : ElComponent{parent}
{
    setCursor(Qt::PointingHandCursor);
}

QString ElAbstractButton::text() const
{
    return _text;
}

void ElAbstractButton::setText(const QString &text)
{
    if (_text == text)
        return;
    _text = text;
    update();
    emit textChanged(_text);
}

ElIcon *ElAbstractButton::icon() const
{
    return _icon;
}

void ElAbstractButton::setIcon(ElIcon *icon, IconStyle style)
{
    if (_icon != icon) {
        delete _icon;
        _icon = icon;
        if (_icon != nullptr) {
            _icon->fillBackground(_palette.color(ElPalette::Foreground));
            _icon->setParent(this);
        }
    }
    _iconStyle = style;
    update();
}

void ElAbstractButton::setIcon(const QString &filename, int iconSize, IconStyle style)
{
    auto icon = new ElIcon(filename, this);
    icon->resize(iconSize, iconSize);
    setIcon(icon, style);
}
